import time
from selenium.webdriver.chrome import webdriver
from selenium.webdriver.common.by import By

from common.doLog import DoLog

logger = DoLog().set_get_logger()
class MyOrderPage():
    
    homePage = (By.XPATH, '/html/body/div[1]/div[1]/div/div/a[1]')
    orderPage = (By.XPATH, '/html/body/div[5]/div[1]/div/div/div/div/a[3]/img')
    unameE = (By.NAME, "username")
    upwdE = (By.NAME, "password")
    regE = (By.NAME, "submit")
    def mydingdan(self, a, b):
        # a:账号 b:密码
        mdd = webdriver.WebDriver()
        # 通过实例打开网页
        mdd.get("http://192.168.106.130/user.php")
        # 登录
        try:
            logger.error("我的订单开始运行")
            mdd.find_element(*self.unameE).send_keys(a)
            mdd.find_element(*self.upwdE).send_keys(b)
            mdd.find_element(*self.regE).click()
            # 进入个人主页
            mdd.find_element(*self.homePage).click()
            # 查看我的订单
            mdd.find_element(*self.orderPage).click()
            time.sleep(3)
        except Exception as e:
            logger.error(f"我的订单运行异常，异常为{e}")
        else:
            logger.error("我的订单运行正常")
        finally:
            logger.error("我的订单运行结束")
if __name__ == '__main__':
    mop = MyOrderPage()
    mop.mydingdan('wsh', "123456")
